/**
 * Copyright © 2016 公司名. All rights reserved.
 * 
 * @Title: BuyerProductRestController.java
 * @Prject: LianniuWeb
 * @Package: com.lianniu.web.buyerProduct.controller
 * @author: lzz
 * @date: 2016年8月31日 上午10:42:19
 * @version: V1.0
 */
package com.lianniu.web.buyerProduct.controller;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.buyerProduct.model.BuyerConsigneeVo;
import com.lianniu.web.buyerProduct.model.CartVo;
import com.lianniu.web.buyerProduct.service.IBuyerInfoService;
import com.lianniu.web.buyerProduct.service.ICartService;
import com.lianniu.web.buyerProduct.service.IProductService;

/**
 * @ClassName: BuyerProductRestController
 * @author: lzz
 * @date: 2016年8月31日 上午10:42:19
 */
@Controller
@RequestMapping("buyer/product/rest")
public class BuyerProductRestController {

    static final Logger LOGGER = Logger.getLogger(BuyerProductRestController.class);

    @Autowired
    private IProductService productService;

    @Autowired
    private IBuyerInfoService buyerInfoService;

    @Autowired
    private ICartService cartService;

    /**
     * 
     * @Title: getProductList
     * @Description: 买家商品列表
     * @author: lzz
     * @param userId
     * @param currPage
     * @return
     * @date: 2016年8月31日 上午10:46:30
     * @return: BaseResult
     */
    @RequestMapping(value = {"getTrendProductList"}, method = RequestMethod.GET)
    @ResponseBody
    public BaseResult getTrendProductList(String userId, Integer currPage, String cateId,String searchName) {
        LOGGER.info("BuyerProductRestController getProductList begin");
        BaseResult result = productService.getTrendList(userId, currPage, cateId,searchName);
        LOGGER.info("BuyerProductRestController getProductList end");
        return result;
    }

    /**
     * 获取行情
     * @param userId
     * @param currPage
     * @param cateId
     * @param searchName
     * @return
     */
    @RequestMapping(value = {"getProductList"}, method = RequestMethod.GET)
    @ResponseBody
    public BaseResult getProductList(String userId, Integer currPage, String cateId,String searchName) {
        LOGGER.info("BuyerProductRestController getProductList begin");
        BaseResult result = productService.getList(userId, currPage, cateId,searchName,false);
        LOGGER.info("BuyerProductRestController getProductList end");
        return result;
    }

    /**
     * @Title: getProductDetail
     * @Description: 买家商品详情
     * @author: lzz
     * @param id
     * @return
     * @date: 2016年8月31日 上午10:48:39
     * @return: BaseResult
     */
    @RequestMapping(value = {"getProductDetail"}, method = RequestMethod.GET)
    @ResponseBody
    public BaseResult getProductDetail(String id) {
        LOGGER.info("BuyerProductRestController getProductDetail begin");
        BaseResult result = productService.getProDetail(id);
        LOGGER.info("BuyerProductRestController getProductDetail end");
        return result;

    }

    /**
     * @Title: getCateTypeOne
     * @Description: 加载一级二级分类
     * @author: lzz
     * @param cateId
     * @return
     * @date: 2016年9月2日 下午12:39:25
     * @return: BaseResult
     */
    @RequestMapping(value = {"buyerCateLoad"}, method = RequestMethod.GET)
    @ResponseBody
    public BaseResult getCateTypeOne(String cateId) {
        LOGGER.info("BuyerProductRestController getCateTypeOne begin");
        BaseResult result = null;
        if (StringUtils.isBlank(cateId) || cateId.equals("-1")){
            result = productService.loadSecondCate("0");
        }else {
            result = productService.loadCate(cateId);
        }
        LOGGER.info("BuyerProductRestController getCateTypeOne end");
        return result;
    }

    /**
     * @Title: getBuyerInfo
     * @Description: 获取买家信息
     * @author: lzz
     * @param userId
     * @return
     * @date: 2016年9月2日 下午12:39:52
     * @return: BaseResult
     */
    @RequestMapping(value = {"getBuyerInfo"}, method = RequestMethod.GET)
    @ResponseBody
    public BaseResult getBuyerInfo(String userId) {
        LOGGER.info("BuyerProductRestController getBuyerInfo begin");
        BaseResult result = buyerInfoService.getBuyerInfoByUserId(userId);
        LOGGER.info("BuyerProductRestController getBuyerInfo end");
        return result;
    }

    /**
     * @Title: addCart
     * @Description: 商品添加到购物车
     * @author: lzz
     * @param cartVo
     * @return
     * @date: 2016年9月2日 下午12:42:43
     * @return: BaseResult
     */
    @RequestMapping(value = {"addCart"}, method = RequestMethod.POST)
    @ResponseBody
    public BaseResult addCart(CartVo cartVo) {
        LOGGER.info("BuyerProductRestController addCart begin");
        BaseResult result = cartService.addCart(cartVo);
        LOGGER.info("BuyerProductRestController addCart end");
        return result;
    }

    /**
     * @Title: getCartList
     * @Description: 查看购物车
     * @author: lzz
     * @param userId
     * @return
     * @date: 2016年9月2日 下午12:44:20
     * @return: BaseResult
     */
    @RequestMapping(value = {"getCartList"}, method = RequestMethod.GET)
    @ResponseBody
    public BaseResult getCartList(String userId,Integer cartPage) {
        LOGGER.info("BuyerProductRestController getCartList begin");
        BaseResult result = cartService.getCartList(userId,cartPage);
        LOGGER.info("BuyerProductRestController getCartList end");
        return result;
    }

    /**
     * @Title: isExits
     * @Description:判断该种商品是否已存于购物车中
     * @author: lzz
     * @param supplyAreaID
     * @return
     * @date: 2016年9月2日 下午12:52:39
     * @return: BaseResult
     */
    @RequestMapping(value = {"isExits"}, method = RequestMethod.GET)
    @ResponseBody
    public BaseResult isExits(String supplyAreaID) {
        LOGGER.info("BuyerProductRestController isExits begin");
        BaseResult result = cartService.isExits(supplyAreaID);
        LOGGER.info("BuyerProductRestController isExits end");
        return result;
    }

    /**
     * @Title: editProSum
     * @Description: 修改购物车某种商品数量
     * @author: lzz
     * @param cartVo
     * @return
     * @date: 2016年9月2日 下午12:57:27
     * @return: BaseResult
     */
    @RequestMapping(value = {"editProSum"}, method = RequestMethod.GET)
    @ResponseBody
    public BaseResult editProSum(CartVo cartVo) {
        LOGGER.info("BuyerProductRestController editProSum begin");
        BaseResult result = cartService.editProSum(cartVo);
        LOGGER.info("BuyerProductRestController editProSum end");
        return result;
    }

    /**
     * 
     * @Title: selectByProductName
     * @Description: 搜索
     * @author: guoconglin
     * @param name
     * @return
     * @date: 2016年9月2日 下午5:39:01
     * @return: BaseResult
     */
    @RequestMapping(value = {"selectByProductName"},
            method = {RequestMethod.GET, RequestMethod.POST})
    public @ResponseBody BaseResult selectByProductName(String userId,Integer currPage,String name,String cateId) {
        LOGGER.info("BuyerProductRestController selectByProductName begin");
        BaseResult baseResult = productService.selectByProductName(userId,currPage,name,cateId);
        LOGGER.info("BuyerProductRestController selectByProductName end");
        return baseResult;
    }

    /**
     * @Title: removeCart
     * @Description: 移除购物车商品
     * @author: Administrator
     * @param ids
     * @return
     * @date: 2016年9月8日 上午9:28:16
     * @return: BaseResult
     */
    @RequestMapping(value = {"removeCart"}, method = RequestMethod.GET)
    @ResponseBody
    public BaseResult removeCart(String ids) {
        LOGGER.info("BuyerProductRestController removeCart begin");
        BaseResult baseResult = cartService.delCart(ids);
        LOGGER.info("BuyerProductRestController removeCart end");
        return baseResult;
    }
    /**
     * @Title: editConsiAddr 
     * @Description: 修改收货地址信息
     * @author: Administrator
     * @param buyerConsignee
     * @return
     * @date: 2016年9月8日 上午9:30:07 
     * @return: BaseResult
     */
    @RequestMapping(value = {"editConsiAddr"}, method = RequestMethod.POST)
    @ResponseBody
    public BaseResult editConsiAddr(BuyerConsigneeVo buyerConsignee) {
        return buyerInfoService.saveConsigneeAddr(buyerConsignee);
    }
    /**
     * @Title: updateSupportPayOnline 
     * @Description: 修改买家是否支持在线支付状态
     * @author: Administrator
     * @param userId
     * @return
     * @date: 2016年10月13日 上午10:11:30 
     * @return: BaseResult
     */
    @RequestMapping(value={"updateSupportPayOnline"})
    @ResponseBody
    public BaseResult updateSupportPayOnline(String userId){
        return buyerInfoService.updateSupportPayOnline(userId);
    }
}
